//---------------------------------------------------------------------------
#ifndef ballH
#define ballH

#define _WIN32_WINNT 0x0501
#include <windows.h>
#include <QtGui>
#include <math.h>
#include "fcn_tables.h"
#include "hbmp.h"

class SBall : public QObject
{
    Q_OBJECT

private:
    QImage ballImage, titleImage, mainImage;
    QImage imageToDraw, titleToDraw;
    QFont pFont;

    void paintBall();
    void paintTitle();
    void paintMainImage();

    qint64 timeofBallDraw, timeofTitleDraw, timeofImageDraw;

    int pWidth;
    int pHeight;
    QRect InnerRect;

    QColor FColor;
    //int FAlpha;
    int FTransp;
    int FShape;
    float FPower;
    int FLuminosity;
    //bool FHole;

    void CalcInnerRect();

public:
    explicit SBall();
    ~SBall();

    void repaint(); // paints all images (very slow)
    void refresh(); // draws ready images to window

    void setTitle(QString text);
    void setTitle(QString text, QColor ballColor);
    void setTitle(QImage &img);
    void setTitle(QImage &img, QColor ballColor);
    void Paint(QImage &img);
    void blurImage(QImage &img, float strength=0.2, QColor color=QColor::Invalid);
    QImage textImage(QString text, QColor color=QColor::Invalid);

    inline QFont font() const {return pFont;}
    inline QColor textColor() const {return (0.3*FColor.red()+0.59*FColor.green()+0.11*FColor.blue() > 128)? QColor(0, 0, 0, 254): QColor(255, 255, 255, 254);}
    inline QColor color() const {return FColor;}
    inline QRect innerRect() const {return InnerRect;}
    inline bool isInnerRectExists() const {return (InnerRect.width()>0 && InnerRect.height()>0);}

    void setPosition(int x, int y);
    void setSize(int a, int b);
//    void setColor(QColor col);
    void setTransparency(int transp);
    void setShape(float shape);
    void setLuminosity(int luminosity);
//    void setHole(bool val);
//    void setActive(bool val);

    int height() const {return pHeight;}
    int width() const {return pWidth;}

signals:
    void imageUpdate(QImage *img);
    void changePosition(QPoint &delta);
};
//---------------------------------------------------------------------------
#endif
